Skip to content

feat(autoware_ndt_scan_matcher): load the NDT implementation as a pluginlib backend - #1527

Merged
mitsudome-r merged 2 commits into
feat/ndt-backend-interfacefrom
feat/ndt-backend-plugin
Nov 24, 2026
Merged

mitsudome-r merged 2 commits into
feat/ndt-backend-interfacefrom
feat/ndt-backend-plugin

Conversation

@xmfcx

@xmfcx xmfcx commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Description

The node now does its NDT computations through the interface autoware::ndt_scan_matcher::NdtBackend from autoware_ndt_scan_matcher_common. It loads the backend with pluginlib, by the name in the parameter ndt.backend. The only backend is ndt_omp, a thin wrapper of ndt_omp. Other packages can add backends without a change to the node.

What changes:

  • src/omp_ndt_backend.hpp/.cpp: the backend ndt_omp, in the plain library autoware_ndt_scan_matcher_omp_backend, registered in plugins.xml. It converts between the types of the interface and the types of ndt_omp. The vectors of the result move, so the conversion copies no large data.
  • ndt_backend_loader.hpp/.cpp: load_ndt_backend(). It uses one pluginlib::ClassLoader that is never destroyed, so a backend library stays loaded until the process ends. An exception from the constructor of a backend gets the name of the backend. The loader is in its own source file, because the pluginlib headers make ndt_scan_matcher_core.cpp (the longest compile of the package) 3.6 s slower.
  • The node, the map update module and the covariance functions use the interface. The node wraps an error from initialize() of the backend in a message with the name of the backend. The copy constructor and the copy assignment become clone(), and new NdtType with set_params() becomes clone_empty(). The calls happen at the same places and under the same locks as before.
  • The covariance estimation (estimate_covariance.cpp) moves from the ndt_omp library into the node library, because it now uses the interface.
  • ndt_omp stays where it is, with the same header paths.

Before and after:

Before: the NDT scan matcher node calls ndt_omp directly, and a GPU NDT must patch the node source.

After: the node uses the NdtBackend interface and loads the ndt_omp backend or a GPU backend with pluginlib.

Related links

Parent Issue:

This PR builds on the rename of the ndt_omp methods (merged) and on the parameter and the interface PRs below it in the stack:

Discussion and benchmark:

How was this PR tested?

New and changed tests:

  • test_omp_ndt_backend (4 tests): the ndt_omp backend gives the same results as ndt_omp called directly, for every field of the result and for the three score functions. It compares with and without a regularization pose. Its copies are independent, and clone_empty() keeps all six parameters.
  • test_ndt_backend_loader (5 tests): pluginlib loads ndt_omp, the backend library is still loaded and a clone works after the instance from pluginlib is gone, and an unknown name throws with the list of the declared backends. The test also expects that class_loader gives no warning about a library that it cannot unload. So it fails if the loader is destroyed while the instance from pluginlib exists. It cannot find a loader that is destroyed while only a clone exists, because the library stays loaded in the test process in that case too.
  • test_map_update_module: the backend comes from pluginlib. A new test runs a rebuild and then an update of the secondary NDT, which uses clone_empty() and clone().
  • Three test backends in the build directory, for the error messages: the constructor of the first one throws, initialize() of the second one throws, and the third one was built with another allocator of Eigen. test_ndt_backend_loader expects the name of the backend in the message for the first one, and the message that names the possible causes for the third one.
  • Three new characterization tests (51 in total): an unknown ndt.backend, a backend whose initialize() throws, and a parameter file without ndt.backend make the node constructor throw. The first test expects the name of the backend in the message, the second one the name and the cause, and the third one the line to add to the parameter file. In the test harness, an override without a value removes that parameter of the parameter file.

The run results are in the Verification block at the end.

Notes for reviewers

  • ndt.backend has no default value in the code, as the parameter guideline requires. Merge order: the parameter PR (feat(autoware_ndt_scan_matcher): add the ndt.backend parameter #1533 above) merges first, then the sync-params PR in autoware_launch merges, and only then this PR. Merging this PR also merges every PR below it, so do not merge the whole stack in one step before the sync-params PR has merged.
  • The library autoware_ndt_scan_matcher_omp_backend is a plain add_library(), not ament_auto_add_library(). ament_auto exports every library that ament_auto_add_library() adds and links it into the later libraries and tests of the package. The node library uses NO_TARGET_LINK_LIBRARIES, so it does not link ndt_omp either. readelf -d shows no NEEDED entry for ndt_omp or the backend library in the node library.
  • The pluginlib class loader is never destroyed (src/ndt_backend_loader.cpp). clone() and clone_empty() make instances with std::make_shared in the backend library, so the library must stay loaded while any instance exists.
  • After a full map rebuild, the old secondary NDT is destroyed outside the lock, before the copy, as in the old code. need_rebuild now becomes false only after the copy exists.
  • A known difference between ndt_omp and the comment of NdtResult::hessian: if a step has the length 0 or is not a number, ndt_omp returns before it stores the hessian, so the result holds the hessian of the alignment before. This PR does not change it, and a comment in omp_ndt_backend.cpp states it.
  • The node loads the backend at the start of its constructor body, before the body creates publishers, subscriptions, services and timers. Only the tf broadcaster and the tf listener exist earlier, because they are members.
  • ndt_omp and the ndt_omp backend stay in this package, and only the interface is in a new package. Earlier decisions rejected an autoware_-prefixed ndt_omp package, and third parties include the ndt_omp headers:

Interface changes

C++ interface

  • Changed in ndt_omp/estimate_covariance.hpp: estimate_xy_covariance_by_multi_ndt() and estimate_xy_covariance_by_multi_ndt_score() take autoware::ndt_scan_matcher::NdtResult and NdtBackend &. propose_poses_to_search() takes autoware::ndt_scan_matcher::NdtResult. ResultOfMultiNdtCovarianceEstimation::ndt_results holds autoware::ndt_scan_matcher::NdtResult. Code that calls these functions with the ndt_omp types must change.
  • Changed in hyper_parameters.hpp: HyperParameters::ndt is autoware::ndt_scan_matcher::NdtParams, and HyperParameters::ndt_backend is new.
  • Changed: MapUpdateModule::NdtType is NdtBackend, and MapUpdateModule::NdtPtrType is NdtBackend::SharedPtr.
  • Added: the header ndt_backend_loader.hpp with the function load_ndt_backend().
  • Removed: hyper_parameters.hpp, map_update_module.hpp, ndt_scan_matcher_core.hpp and ndt_omp/estimate_covariance.hpp no longer include multigrid_ndt_omp.h. Code that got the ndt_omp types through these headers must include it.
  • Removed: the library multigrid_ndt_omp no longer contains the covariance estimation. It is in the node library.

ROS parameters

  • Changed: the node now declares and requires ndt.backend. The parameter PR below this one added it to the parameter file. Without it, the node stops with this message: The parameter 'ndt.backend' is not set. Add the line `backend: "ndt_omp"` under `ndt:` in the parameter file of autoware_ndt_scan_matcher.

Effects on system behavior

With the ndt_omp backend, the node computes the same results with the same code. A parameter file without ndt.backend (for example, a private copy of the file) now makes the node stop at startup, until it gets this one line.

AI usage

AI usage: Written with Claude Code. I set the design, the requirements and the PR structure. Claude Code wrote the code, the tests and this description.

Self-review: A review with a clean context read the full diff of this PR against its base branch, the three files with rebase conflicts, and the ndt_omp code behind the wrapper. Three rounds ran: two on the code and one on this description. The first round found no correctness bug and two small items: no test for the message of a missing ndt.backend, and a const test object that a callback changes. Both are fixed, and the description has the corrections from the third round.

Verification: On Jazzy, the two packages build after the rebase on the diagnostics change, and `colcon test-result` reports 185 results with 0 failures. The rosbag comparison, the runtime and the build times are from the version before that rebase.

Build and tests

Jazzy, x86_64, an incremental build in the local workspace, this PR at 169fa3eb. The current head 4bdcb683 has the same files: GitHub rebased it on main after the rename PR merged. The dependencies came from a local workspace install.

  • colcon build --symlink-install --packages-select autoware_ndt_scan_matcher_common autoware_ndt_scan_matcher --cmake-args -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=--coverage: Summary: 2 packages finished [49.7s].
  • colcon test --packages-select autoware_ndt_scan_matcher_common autoware_ndt_scan_matcher --event-handlers console_cohesion-, then colcon test-result --test-result-base build/<package> for each package: Summary: 23 tests, 0 errors, 0 failures, 4 skipped and Summary: 162 tests, 0 errors, 0 failures, 48 skipped. All skipped results are cppcheck results.
  • The characterization test ran 51 tests, with MissingBackendParameterThrowsAtConstruction.
  • A reviewer's clean build in a separate workspace, on the same code without the last two README changes of autoware_ndt_scan_matcher_common, printed Summary: 185 tests, 0 errors, 0 failures, 52 skipped.
  • Not run locally: Humble, and a build with ENABLE_AGNOCAST=1. The characterization tests do not run in an agnocast build.

Node start with a missing or wrong ndt.backend

ros2 run autoware_ndt_scan_matcher autoware_ndt_scan_matcher_node --ros-args --params-file <file>, on the pushed head 018049bff, without the fix commit of the interface PR and without the last commit of this PR:

  • Without backend in the file: The parameter 'ndt.backend' is not set. Add the line ...
  • -p ndt.backend:=3: InvalidParameterTypeException
  • -p 'ndt.backend:=""': Failed to load the NDT backend ''. ... Declared types are ndt_omp

Comparison with main

On the version before the rebase on the diagnostics change. It did not run again after that rebase.

  • With the harness of the benchmark: main and this stack in two overlay workspaces, Release, on the sample rosbag (Ryzen 9 5900X).
  • In 3 open-loop runs, the poses, iteration counts, TP and NVTL are bit-identical to main for every scan that both sides recorded (283 or 284 of 284 in each run). In two runs, one side recorded one scan fewer: once main and once this stack.
  • Runtime: in 4 open-loop runs of each, taken in turns, the median time per scan is 3.58 to 3.88 ms on main and 3.60 to 3.76 ms with this stack.
  • Clean build in Release, no ccache, median of 3 runs taken in turns: 57.4 s wall time for the two packages, against 72.5 s for autoware_ndt_scan_matcher on main. The CPU time (user and system) is 116.8 s against 103.1 s. The ndt_omp backend library compiles in parallel with the node library.
  • With the pluginlib headers in ndt_scan_matcher_core.cpp, that file took 3.6 s longer to compile. So the loader is in its own source file.

Other backends

On the version before the rebase on the diagnostics change.

  • A backend package outside this repository loads, and the same package built with -mavx does not load (see the interface PR below this one).
  • A prototype backend for ndt_cuda (the package ndt_cuda_autoware_backend, a wrapper of about 180 lines) implements the interface without a change to the interface or to the node. In open loop on the sample rosbag with a tiled map, the node with this backend takes a median of 0.40 ms per scan, against 3.75 ms with ndt_omp. The largest position difference to ndt_omp is 1.2 cm.

CI

On this head 4bdcb683:

  • The build-and-test jobs pass on Humble, Jazzy, Jazzy agnocast, Humble above and Jazzy above. clang-tidy-diff passes on Humble and Jazzy.
  • codecov/project fails, and codecov/patch passes.
  • pre-commit-optional fails on two dead links in localization/autoware_pose_initializer/README.md, which this PR does not touch.

@xmfcx
xmfcx added this pull request to stack #1529 November 9, 2026 19:00
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Thank you for contributing to the Autoware project!

🚧 If your pull request is in progress, switch it to draft mode.

Please ensure:

@xmfcx xmfcx self-assigned this Nov 9, 2026
@xmfcx xmfcx added the run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci) label Nov 9, 2026
@xmfcx
xmfcx removed this pull request from stack #1529 November 9, 2026 19:52
@xmfcx
xmfcx force-pushed the feat/ndt-backend-plugin branch from 36742b5 to 28dce94 Compare November 9, 2026 19:53
@xmfcx
xmfcx changed the base branch from refactor/ndt-omp-snake-case-api to refactor/ndt-omp-package November 9, 2026 19:53
@xmfcx
xmfcx added this pull request to stack #1532 November 9, 2026 19:53
@codecov

codecov Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.51%. Comparing base (a8ddf9b) to head (4bdcb68).

Additional details and impacted files
@@                      Coverage Diff                       @@
##           feat/ndt-backend-interface    #1527      +/-   ##
==============================================================
- Coverage                       72.59%   72.51%   -0.08%     
==============================================================
  Files                             500      505       +5     
  Lines                           27778    28045     +267     
  Branches                        13128    13140      +12     
==============================================================
+ Hits                            20165    20337     +172     
- Misses                           7531     7605      +74     
- Partials                           82      103      +21     
Flag Coverage Δ *Carryforward flag
daily-humble 82.29% <ø> (-0.01%) ⬇️ Carriedforward from a8ddf9b
daily-jazzy 82.36% <ø> (-0.01%) ⬇️ Carriedforward from a8ddf9b
differential-humble 76.41% <100.00%> (+76.41%) ⬆️
differential-jazzy 62.69% <100.00%> (+62.69%) ⬆️
total 50.35% <ø> (+<0.01%) ⬆️ Carriedforward from a8ddf9b
total-humble 82.29% <ø> (-0.01%) ⬇️ Carriedforward from a8ddf9b
total-humble-agnocast 70.82% <ø> (+<0.01%) ⬆️ Carriedforward from a8ddf9b
total-jazzy 82.35% <ø> (-0.01%) ⬇️ Carriedforward from a8ddf9b
total-jazzy-agnocast 70.72% <ø> (+<0.01%) ⬆️ Carriedforward from a8ddf9b

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xmfcx
xmfcx removed this pull request from stack #1532 November 9, 2026 20:50
@xmfcx
xmfcx force-pushed the feat/ndt-backend-plugin branch from 28dce94 to a37836b Compare November 9, 2026 20:50
@xmfcx
xmfcx changed the base branch from refactor/ndt-omp-package to feat/ndt-backend-interface November 9, 2026 20:50
@xmfcx
xmfcx added this pull request to stack #1535 November 9, 2026 20:50
@xmfcx
xmfcx force-pushed the feat/ndt-backend-plugin branch 2 times, most recently from bb7568c to fdbd149 Compare November 9, 2026 22:02
@xmfcx
xmfcx force-pushed the feat/ndt-backend-plugin branch 6 times, most recently from c5895d6 to 7613292 Compare November 10, 2026 03:18
@xmfcx
xmfcx marked this pull request as ready for review November 10, 2026 04:29
@xmfcx
xmfcx requested a review from a team as a code owner November 10, 2026 04:29
@xmfcx
xmfcx removed this pull request from stack #1535 November 23, 2026 14:27
@xmfcx
xmfcx force-pushed the feat/ndt-backend-plugin branch from 7613292 to f6dc2f2 Compare November 23, 2026 14:27
Base automatically changed from feat/ndt-backend-interface to refactor/ndt-omp-snake-case-api November 23, 2026 14:27
@xmfcx
xmfcx added this pull request to stack #1560 November 23, 2026 14:33
@xmfcx
xmfcx removed this pull request from stack #1560 November 23, 2026 14:42
@xmfcx
xmfcx force-pushed the feat/ndt-backend-plugin branch from f6dc2f2 to a982e19 Compare November 23, 2026 14:43
@xmfcx
xmfcx changed the base branch from refactor/ndt-omp-snake-case-api to feat/ndt-backend-interface November 23, 2026 14:43
@xmfcx
xmfcx added this pull request to stack #1561 November 23, 2026 14:44
@xmfcx
xmfcx force-pushed the feat/ndt-backend-plugin branch 2 times, most recently from 018049b to 169fa3e Compare November 23, 2026 17:42
…ginlib backend

The node now does its NDT computations through the interface NdtBackend from autoware_ndt_scan_matcher_common. It loads the backend with pluginlib, by the name in the parameter ndt.backend. Other packages can add backends without a change to the node.

- The backend "ndt_omp" is a thin wrapper of ndt_omp in a plain library of this package, so that no library links it. It converts between the types of the interface and the types of ndt_omp.
- The node loads backends through one pluginlib class loader that is never destroyed. So a backend library stays loaded until the process ends, and the clones of a backend stay valid. The node loads the backend before it creates its interfaces.
- The copy constructor and the copy assignment of the NDT object become clone(), and the new empty NDT of a full map rebuild becomes clone_empty(). After a rebuild, need_rebuild becomes false only after the copy to the secondary NDT exists.
- The covariance estimation uses the interface and is now part of the node library.

ndt.backend has no default value in the code, as the parameter guideline requires. Without the parameter, the node stops with a message that names the parameter and the line to add.

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>
…ackend

Add a characterization test for a parameter file without ndt.backend. An override without a value in the test harness now removes that parameter of the yaml.

Remove const from the LogSpy of the loader test, because class_loader changes it through log().

Signed-off-by: Mete Fatih Cırıt <mfc@autoware.org>
@xmfcx
xmfcx force-pushed the feat/ndt-backend-plugin branch from 169fa3e to 4bdcb68 Compare November 23, 2026 17:45
@xmfcx
xmfcx requested a review from mitsudome-r November 23, 2026 20:14
@mitsudome-r
mitsudome-r merged commit c8811a7 into main Nov 24, 2026
48 of 50 checks passed
@mitsudome-r
mitsudome-r deleted the feat/ndt-backend-plugin branch November 24, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run:build-and-test-differential Mark to enable build-and-test-differential workflow. (used-by-ci)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants